﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BDCS.Model;
using BDCS.BLL;

namespace BDCS.UI
{
    public partial class AlterSubBuildAttributes : Form
    {
        #region 成员字段
        private BDCS.Model.T_SubBuildAttributes modelSubBuildAttribute;
        private int sbaid;
        private int sbtid;
        private string sbaContent;
        private string sbaContentTwo;
        private string sbaDescribe;
        private string sbaDescribeTwo;
        private BDCS.BLL.T_SubBuildAttributes bllSubBuildAttribute;
        #endregion
        #region 构造函数
        public AlterSubBuildAttributes()
        {
            InitializeComponent();
        }
        public AlterSubBuildAttributes(Model.T_SubBuildAttributes subBuildAttribute)
        {
            this.modelSubBuildAttribute = subBuildAttribute;
            InitializeComponent();
        }
        #endregion
        #region 成员事件
        private void AlterSubBuildAttributes_Load(object sender, EventArgs e)
        {
            this.txtSubBuildAttributeName.Text = this.modelSubBuildAttribute.SBAContent;
            this.txtSubBuildAttributeDescribe.Text = this.modelSubBuildAttribute.SBADescribe;
            this.sbaid = this.modelSubBuildAttribute.SBAID;
            this.sbtid = this.modelSubBuildAttribute.SBTID;
            this.sbaContent = this.modelSubBuildAttribute.SBAContent;
            this.sbaDescribe = this.modelSubBuildAttribute.SBADescribe;
            this.sbaContentTwo = this.modelSubBuildAttribute.SBAContent;
            this.sbaDescribeTwo = this.modelSubBuildAttribute.SBADescribe;
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            modelSubBuildAttribute = new Model.T_SubBuildAttributes();
            modelSubBuildAttribute.SBTID = this.sbtid;
            modelSubBuildAttribute.SBAID = this.sbaid;
            modelSubBuildAttribute.SBAContent = this.txtSubBuildAttributeName.Text.Trim();
            modelSubBuildAttribute.SBADescribe = this.txtSubBuildAttributeDescribe.Text.Trim();
            bllSubBuildAttribute = new BLL.T_SubBuildAttributes();
            if (this.txtSubBuildAttributeName.Text.Trim() != this.sbaContent || this.txtSubBuildAttributeDescribe.Text.Trim() != this.sbaDescribe)
            {
                try
                {
                    if (bllSubBuildAttribute.Update(modelSubBuildAttribute) == true)
                    {
                        sbaContent = txtSubBuildAttributeName.Text.Trim();
                        sbaDescribe = txtSubBuildAttributeDescribe.Text.Trim();
                        BDCS.Common.TreeViewState.IsChangedAttribute = true;
                        MessageBox.Show("修改成功！");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
            else
            {
                MessageBox.Show("没有修改任何内容，不需要提交！");
            }
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.txtSubBuildAttributeName.Text = this.sbaContentTwo;
            this.txtSubBuildAttributeDescribe.Text = this.sbaDescribeTwo;
            if (sbaContent != sbaContentTwo || sbaDescribe != sbaDescribeTwo)
            {
                modelSubBuildAttribute = new Model.T_SubBuildAttributes();
                modelSubBuildAttribute.SBAID = this.sbaid;
                modelSubBuildAttribute.SBTID = this.sbtid;
                modelSubBuildAttribute.SBAContent = this.sbaContentTwo;
                modelSubBuildAttribute.SBADescribe = this.sbaDescribeTwo;
                bllSubBuildAttribute = new BLL.T_SubBuildAttributes();
                try
                {
                    bllSubBuildAttribute.Update(modelSubBuildAttribute);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
        }
        #endregion
    }
}
